package travianBot;

import java.net.URLEncoder;
import java.util.HashMap;

public class LinkMaker {
	
	public static final String SERVER_HTTP="http://s1.travian.co.uk/";

	public static String LOGIN_PAGE=SERVER_HTTP+"login.php";
	
	public static String VILLAGE_PAGE=SERVER_HTTP+"dorf1.php";
	
	public static String BUILDINGS_PAGE=SERVER_HTTP+"dorf2.php";
	
	public static String getLoadVillageLink(Village village){
		//http://s1.travian.co.uk/dorf1.php?newdid=105173
		return SERVER_HTTP+"dorf1.php?newdid="+village.getId();
	}
	
	public static String getUpgradeResourcePageLink(ResourceEntry resourceEntry){
		//http://s1.travian.co.uk/build.php?id=12
		return SERVER_HTTP+"build.php?id="+resourceEntry.location;
	}
	
	public static String getBuildLink(){
		//http://s1.travian.co.uk/build.php?id=12
		return SERVER_HTTP+"build.php";
	}
	
	public static String getBuildingPageLink(ResourceEntry resourceEntry){
		return SERVER_HTTP+"build.php?id="+resourceEntry.location;
	}
	
	public static String completeRelativeLink(String relativeLink){
		return SERVER_HTTP+relativeLink;
	}
	
	public static String getBuildingPageLink(ResourceEntry resourceEntry, HashMap<String, String> params){
		StringBuilder out = new StringBuilder();
		
		for (String key : params.keySet()) {
			out.append("&"+URLEncoder.encode(key)+"="+URLEncoder.encode(params.get(key)));
		}
		return SERVER_HTTP+"build.php?id="+resourceEntry.location+out.toString();
	}
}
